<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>CodingDGSun's Blog</title><meta name="author" content="CodingDGSun"><meta name="copyright" content="CodingDGSun"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta property="og:type" content="website">
<meta property="og:title" content="CodingDGSun&#39;s Blog">
<meta property="og:url" content="https://sunjie23.gitee.io/codingdgsun/page/5/index.html">
<meta property="og:site_name" content="CodingDGSun&#39;s Blog">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/CodingDGSun/images-db@master/Blog/头像.7horht40yvwg.jpg">
<meta property="article:author" content="CodingDGSun">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/CodingDGSun/images-db@master/Blog/头像.7horht40yvwg.jpg"><link rel="shortcut icon" href="/codingdgsun/img/favicon.png"><link rel="canonical" href="https://sunjie23.gitee.io/codingdgsun/page/5/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/codingdgsun/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/codingdgsun/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'CodingDGSun\'s Blog',
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2022-01-17 14:06:45'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/codingdgsun/atom.xml" title="CodingDGSun's Blog" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://cdn.jsdelivr.net/gh/CodingDGSun/images-db@master/Blog/头像.7horht40yvwg.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/codingdgsun/archives/"><div class="headline">Articles</div><div class="length-num">59</div></a></div></div></div><hr/></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header"><nav id="nav"><span id="blog_name"><a id="site-name" href="/codingdgsun/">CodingDGSun's Blog</a></span><div id="menus"><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">CodingDGSun's Blog</h1></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="post_cover left_radius"><a href="/codingdgsun/2021/07/03/Java%E4%B8%AD%E7%9A%84%E6%B3%A8%E8%A7%A3Annotation/" title="Java中的注解Annotation">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java中的注解Annotation"></a></div><div class="recent-post-info"><a class="article-title" href="/codingdgsun/2021/07/03/Java%E4%B8%AD%E7%9A%84%E6%B3%A8%E8%A7%A3Annotation/" title="Java中的注解Annotation">Java中的注解Annotation</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2021-07-03T09:23:51.000Z" title="Created 2021-07-03 17:23:51">2021-07-03</time></span></div><div class="content">基本Annotation

@Override
@Deprecated
@SuppressWarnings
@SafeVarargs


@Override用来指定方法重载，它可以强制一个子类必须覆盖父类的方法。

主要是帮助我们避免一些低级错误，例如：父类中有个run()方法，子类中的方法名不小心写成了runn()，在程序编译时候会报错提示。
只能作用于方法，不能作用于其他程序元素。

@Deprecated用于表示某个元素（类、方法等）已过时，当其他程序使用已过时的类、方法时，编译器将会给出警告。

虽然出现警告，但不影响使用，使用还是可以使用的

123456789101112131415//父类，其中标记为test()方法是过时方法。public class SupperClass &#123;    @Deprecated    public void test()&#123;        System.out.println(&quot;我是父类过时方法test&quot;);    &#125;&#125;//子类调用是，编译会警告提示，方法已经过时。public cl ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/codingdgsun/2021/07/02/Java%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F/" title="Java中的线程生命周期">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java中的线程生命周期"></a></div><div class="recent-post-info"><a class="article-title" href="/codingdgsun/2021/07/02/Java%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F/" title="Java中的线程生命周期">Java中的线程生命周期</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2021-07-02T03:12:54.000Z" title="Created 2021-07-02 11:12:54">2021-07-02</time></span></div><div class="content">线程的生命周期
新建（New）
就绪（Runnable）
运行（Running）
阻塞（Blocked）
死亡（Dead）


新建和就绪状态新建
当程序使用new关键字创建了一个线程后，该线程就处于新建状态，此时它和其他的Java对象一样，仅仅由Java虚拟机为其分配内存，并初始化其成员变量的值。此时的线程对象没有表现出任何线程的动态特征，程序不会执行线程的线程执行体。

就绪
当线程对象调用了start()方法之后，该线程处于就绪状态，Java虚拟机会为其创建方法调用栈和程序计数器，处于这个状态中的线程并没有开始运行，只是表示该线程可以运行。至于该线程何时开始运行，取决于JVM里线程调度器的调度。

特别注意

启动线程使用start()方法，而不是run()方法。永远不要调用线程对象的run()方法。
调用start()方法来启动线程，系统会把run()方法当成线程执行体来处理。
但如果直接调用线程对象的run()方法，则run()方法立即就会被执行，而是在run()方法返回之前其他线程无法并发执行。也就是说，系统把线程对象当成一个普通对象，而run()方法也是一个普通方法，而不 ...</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/codingdgsun/2021/07/02/Java%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%88%9B%E5%BB%BA%E5%92%8C%E5%90%AF%E5%8A%A8/" title="Java中的线程创建和启动">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java中的线程创建和启动"></a></div><div class="recent-post-info"><a class="article-title" href="/codingdgsun/2021/07/02/Java%E4%B8%AD%E7%9A%84%E7%BA%BF%E7%A8%8B%E5%88%9B%E5%BB%BA%E5%92%8C%E5%90%AF%E5%8A%A8/" title="Java中的线程创建和启动">Java中的线程创建和启动</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2021-07-02T03:07:50.000Z" title="Created 2021-07-02 11:07:50">2021-07-02</time></span></div><div class="content">Java使用Thread类代表线程，所有的线程对象都必须是Thread类或者其子类的实例。每个线程的作用是完成一定的任务，实际上就是执行一段程序流（一段顺序执行的代码）。Java使用线程执行体来代表这段程序流。

继承Thread类创建线程类通过继承Thread类来创建并启动多线程的步骤如下：

定义Thread类的子类，并重写该类的run()方法，该run()方法的方法体就代表了线程需要完成的任务。因此把run()方法称为线程执行体。
创建Thread子类的实例，即创建了线程对象。
调用线程对象的start()方法来启动该线程。

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970public class MyThread extends Thread &#123;    @Override    public void run() &#123;        for (in ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/codingdgsun/2021/07/01/Java%E4%B8%AD%E7%9A%84%E7%A8%8B%E5%BA%8F%E3%80%81%E8%BF%9B%E7%A8%8B%E3%80%81%E7%BA%BF%E7%A8%8B/" title="Java中的程序、进程、线程">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java中的程序、进程、线程"></a></div><div class="recent-post-info"><a class="article-title" href="/codingdgsun/2021/07/01/Java%E4%B8%AD%E7%9A%84%E7%A8%8B%E5%BA%8F%E3%80%81%E8%BF%9B%E7%A8%8B%E3%80%81%E7%BA%BF%E7%A8%8B/" title="Java中的程序、进程、线程">Java中的程序、进程、线程</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2021-07-01T08:47:35.000Z" title="Created 2021-07-01 16:47:35">2021-07-01</time></span></div><div class="content">程序、进程、线程的关系
程序：操作系统中通常都支持同时运行多个任务，一个任务就是一个程序。程序只是一个静态的指令集合。
进程：每个运行中的程序，就是一个进程。进程是一个正在系统中活动的指令集合。
线程：当一个程序运行时，内部可能包含了多个顺序执行流，每个顺序执行流就是一个线程。


并行性和并发性
并行性：指在同一时刻，有多条指令在多个处理器上同时执行。
并发性：指在同一时刻，只能有一条指令执行，但多个进程指令被快速轮换执行，使得宏观上具有多个进程同时执行的效果。

</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/codingdgsun/2021/07/01/Java%E4%B8%AD%E7%9A%84IO%E6%B5%81/" title="Java中的IO流">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java中的IO流"></a></div><div class="recent-post-info"><a class="article-title" href="/codingdgsun/2021/07/01/Java%E4%B8%AD%E7%9A%84IO%E6%B5%81/" title="Java中的IO流">Java中的IO流</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2021-07-01T07:19:34.000Z" title="Created 2021-07-01 15:19:34">2021-07-01</time></span></div><div class="content">Java中的IO流分类
输入IO流
输入字节流（InputStream）
处理流
缓冲流（BufferedInputStream）
转换流
数据流（DataInputStream）


标准流（System.in（InputStream））


输入字符流（Reader）
处理流
缓冲流（BufferedReader）
转换流（InputStreamReader）
数据流


标准流





UML关系图如下所示PantUML语法12A &lt;|-- B //B继承AC &lt;|... D //D实现了C

12345678910111213141516171819202122232425262728293031323334353637@startumlabstract class InputStream&#123;&#125;class BufferedInputStream&#123;&#125;class FilterInputStream&#123;&#125;class DataInputStream&#123;&#125;interface DataInput&#12 ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/codingdgsun/2021/06/30/Java%E4%B8%ADCollections%E5%92%8CArrays%E7%B1%BB/" title="Java中Collections和Arrays类">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java中Collections和Arrays类"></a></div><div class="recent-post-info"><a class="article-title" href="/codingdgsun/2021/06/30/Java%E4%B8%ADCollections%E5%92%8CArrays%E7%B1%BB/" title="Java中Collections和Arrays类">Java中Collections和Arrays类</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2021-06-30T15:28:42.000Z" title="Created 2021-06-30 23:28:42">2021-06-30</time></span></div><div class="content">Collections
Collections是个java.util下的专用静态类，它包含有各种有关集合操作的静态方法。提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作.
  1234567891011public static void main(String[] args) &#123;    List list = new ArrayList();    list.add(17);    list.add(11);    list.add(65);    list.add(36);    Collections.sort(list);    System.out.println(list);//[11, 17, 36, 65]&#125;



Arrays
Arrays是个java.util下的专用静态类，它包含有各种有关操作数组 ，提供搜索、排序、复制等静态方法。
  123456public static void main(String[] args) &#123;    int[] array = new int[]&#123;11, 4, 23, 16, ...</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/codingdgsun/2021/06/30/Java%E4%B8%AD%E7%9A%84%E9%9B%86%E5%90%88/" title="Java中的集合">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java中的集合"></a></div><div class="recent-post-info"><a class="article-title" href="/codingdgsun/2021/06/30/Java%E4%B8%AD%E7%9A%84%E9%9B%86%E5%90%88/" title="Java中的集合">Java中的集合</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2021-06-30T07:05:52.000Z" title="Created 2021-06-30 15:05:52">2021-06-30</time></span></div><div class="content">Java集合体系
Set（接口）：代表无序、不可重复的集合
List（接口）：代表有序、重复的集合
Map（接口）：代表具有映射关系的集合
Queue（接口）：代表队列集合

集合类和数组区别
数组元素既可以是基本类型的值，也可以是对象（实际上保存的是对象的引用变量）。
集合里只能保存对象（实际上保存的是对象的引用变量，但通常习惯认为集合里保存的是对象）

Java的集合类主要由两个接口派生而出，他们是Java集合框架的根接口，这两个接口又包含了一些子接口或实现类。

Collection（接口）
Map（接口）

UML关系图如下所示PantUML语法12A &lt;|-- B //B继承AC &lt;|... D //D实现了C

Collection123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888 ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/codingdgsun/2021/06/29/Java%E4%B8%AD%E7%9A%84%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6%E7%AC%A6/" title="Java中的访问控制符">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java中的访问控制符"></a></div><div class="recent-post-info"><a class="article-title" href="/codingdgsun/2021/06/29/Java%E4%B8%AD%E7%9A%84%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6%E7%AC%A6/" title="Java中的访问控制符">Java中的访问控制符</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2021-06-29T15:30:22.000Z" title="Created 2021-06-29 23:30:22">2021-06-29</time></span></div><div class="content">Java提供了4种访问控制级别
private
不加任何访问控制符的访问控制级别（default)
protected
public

从上到下，访问控制级别由小到大。
权限介绍
private：当前类访问权限。如果类中的成员（包括属性、方法和构造器等）使用private访问控制符来修饰，则这个成员只能在当前类的内部被访问。
default：包访问权限。如果类中的成员（包括属性、方法和构造器等）或者一个外部类，不用任何访问控制符修饰，我们就称它是包访问权限。default访问控制的成员或外部类可以被相同包下的其他类访问。
protected：子类访问权限。如果类中的成员（包括属性、方法和构造器等）使用protected访问控制符来修饰，则这个成员即可以被同一个包中的其他类访问，也可以被不同包中的子类访问。
public：公共访问权限。这是一个最宽松的访问控制级别。如果类中的成员（包括属性、方法和构造器等）或者一个外部类，使用public访问控制符来修饰，那么这个成员或者外部类就可以被所有类访问，不管访问类和被访问类是否处于同一个包中，不管是否具有父子继承关系。

外部类只能有两种访问控 ...</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/codingdgsun/2021/06/29/Java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B8%89%E5%A4%A7%E7%89%B9%E5%BE%81/" title="Java面向对象三大特征">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java面向对象三大特征"></a></div><div class="recent-post-info"><a class="article-title" href="/codingdgsun/2021/06/29/Java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B8%89%E5%A4%A7%E7%89%B9%E5%BE%81/" title="Java面向对象三大特征">Java面向对象三大特征</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2021-06-29T05:30:32.000Z" title="Created 2021-06-29 13:30:32">2021-06-29</time></span></div><div class="content">面向对象三大特征
封装

对象的状态信息隐藏在对象内部，不允许外部程序直接访问对象内部信息，而是通过类所提供的方法来实现对内部信息的操作和访问。


继承

是实现软件复用的重要手段，Java的继承具有单继承特点，每个子类只有一个直接父类，使用extends来实现。
实现继承的类被称为：子类，被继承的类被称为：父类或者基类或者超类。
父类与子类的关系是一种一般和特殊的关系。即，父类（一般），子类（特殊）。比如：水果和苹果的关系，苹果继承了水果，苹果是水果的子类，则苹果是一种特殊的水果。

123public class SubClass extends SuperClass&#123;    //类定义部分&#125;
多态

Java引用变量有两个类型，一个是编译时类型，一个是运行时类型。

编译时类型由声明该变量时使用的类型决定，运行时类型由实际赋给该变量的对象决定。

如果编译时类型与运行时类型不一致，就可能出现所谓的多态。
123456789101112131415161718192021222324252627282930313233343536373839404142434 ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/codingdgsun/2021/06/29/Java%E4%B8%AD%E7%9A%84%E6%95%B0%E7%BB%84%E7%B1%BB%E5%9E%8B/" title="Java中的数组类型">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java中的数组类型"></a></div><div class="recent-post-info"><a class="article-title" href="/codingdgsun/2021/06/29/Java%E4%B8%AD%E7%9A%84%E6%95%B0%E7%BB%84%E7%B1%BB%E5%9E%8B/" title="Java中的数组类型">Java中的数组类型</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2021-06-28T22:25:21.000Z" title="Created 2021-06-29 06:25:21">2021-06-29</time></span></div><div class="content">数组中的元素类型是唯一的，只能存储一种类型，不能存储多种类型数据。数组是一种引用类型。定义数组12type[] arrayName; //推荐使用这种来定义数组type arrayName[];

初始化数组
静态初始化
初始化时，由程序员显示指定每个数组元素的初始值，由系统决定数组的长度。



12345type[] arrayName = new type[] &#123;element1, element2, element3&#125;;//比如int[] a = new int[]&#123;5, 6, 7&#125;;int[] b = &#123;6, 7, 8&#125;;Object[] obj = new String[]&#123;&quot;hello&quot;, &quot;world&quot;&#125;;


动态初始化
初始化时，程序员只指定数组长度，由系统为数组元素分配初始值。
整数类型（bype、short、int、long），数组元素的初始值为0
浮点类型（float、double），数组元素的初始值为0.0
字符类型（char），数组元素的 ...</div></div></div><nav id="pagination"><div class="pagination"><a class="extend prev" rel="prev" href="/codingdgsun/page/4/#content-inner"><i class="fas fa-chevron-left fa-fw"></i></a><a class="page-number" href="/codingdgsun/">1</a><span class="space">&hellip;</span><a class="page-number" href="/codingdgsun/page/4/#content-inner">4</a><span class="page-number current">5</span><a class="page-number" href="/codingdgsun/page/6/#content-inner">6</a><a class="extend next" rel="next" href="/codingdgsun/page/6/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://cdn.jsdelivr.net/gh/CodingDGSun/images-db@master/Blog/头像.7horht40yvwg.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">CodingDGSun</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/codingdgsun/archives/"><div class="headline">Articles</div><div class="length-num">59</div></a></div></div><a class="button--animated" id="card-info-btn" href="https://sunjie23.gitee.io/codingdgsun"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/codingdgsun/2022/01/17/React%E9%A1%B9%E7%9B%AEbuild%E5%A4%B1%E8%B4%A5%E4%B9%8BMiniCssExtractPlugin/" title="React项目build失败之MiniCssExtractPlugin"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="React项目build失败之MiniCssExtractPlugin"/></a><div class="content"><a class="title" href="/codingdgsun/2022/01/17/React%E9%A1%B9%E7%9B%AEbuild%E5%A4%B1%E8%B4%A5%E4%B9%8BMiniCssExtractPlugin/" title="React项目build失败之MiniCssExtractPlugin">React项目build失败之MiniCssExtractPlugin</a><time datetime="2022-01-17T06:03:03.000Z" title="Created 2022-01-17 14:03:03">2022-01-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/codingdgsun/2022/01/17/React%E9%A1%B9%E7%9B%AE%E6%9E%84%E5%BB%BA%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" title="React项目构建常用命令"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="React项目构建常用命令"/></a><div class="content"><a class="title" href="/codingdgsun/2022/01/17/React%E9%A1%B9%E7%9B%AE%E6%9E%84%E5%BB%BA%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" title="React项目构建常用命令">React项目构建常用命令</a><time datetime="2022-01-17T06:01:56.000Z" title="Created 2022-01-17 14:01:56">2022-01-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/codingdgsun/2022/01/17/Mac-OS%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%80%E4%B8%AAReact%E9%A1%B9%E7%9B%AE/" title="Mac OS初始化一个React项目"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Mac OS初始化一个React项目"/></a><div class="content"><a class="title" href="/codingdgsun/2022/01/17/Mac-OS%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%80%E4%B8%AAReact%E9%A1%B9%E7%9B%AE/" title="Mac OS初始化一个React项目">Mac OS初始化一个React项目</a><time datetime="2022-01-17T05:58:21.000Z" title="Created 2022-01-17 13:58:21">2022-01-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/codingdgsun/2022/01/17/MySQL%E8%AF%AD%E6%B3%95%E5%85%A5%E9%97%A8%EF%BC%88%E4%BA%8C%EF%BC%89/" title="MySQL语法入门（二）"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="MySQL语法入门（二）"/></a><div class="content"><a class="title" href="/codingdgsun/2022/01/17/MySQL%E8%AF%AD%E6%B3%95%E5%85%A5%E9%97%A8%EF%BC%88%E4%BA%8C%EF%BC%89/" title="MySQL语法入门（二）">MySQL语法入门（二）</a><time datetime="2022-01-17T05:54:56.000Z" title="Created 2022-01-17 13:54:56">2022-01-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/codingdgsun/2022/01/17/Java%E4%B8%AD%E5%B8%B8%E8%A7%81%E9%9D%A2%E8%AF%95%E9%A2%98%E4%BA%8C%EF%BC%88%E7%AE%80%E5%8D%95%EF%BC%89/" title="Java中常见面试题二（简单）"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/codingdgsun/img/404.jpg'" alt="Java中常见面试题二（简单）"/></a><div class="content"><a class="title" href="/codingdgsun/2022/01/17/Java%E4%B8%AD%E5%B8%B8%E8%A7%81%E9%9D%A2%E8%AF%95%E9%A2%98%E4%BA%8C%EF%BC%88%E7%AE%80%E5%8D%95%EF%BC%89/" title="Java中常见面试题二（简单）">Java中常见面试题二（简单）</a><time datetime="2022-01-17T05:53:56.000Z" title="Created 2022-01-17 13:53:56">2022-01-17</time></div></div></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>Archives</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/codingdgsun/archives/2022/01/"><span class="card-archive-list-date">January 2022</span><span class="card-archive-list-count">9</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/codingdgsun/archives/2021/12/"><span class="card-archive-list-date">December 2021</span><span class="card-archive-list-count">21</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/codingdgsun/archives/2021/07/"><span class="card-archive-list-date">July 2021</span><span class="card-archive-list-count">15</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/codingdgsun/archives/2021/06/"><span class="card-archive-list-date">June 2021</span><span class="card-archive-list-count">14</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>Info</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">Article :</div><div class="item-count">59</div></div><div class="webinfo-item"><div class="item-name">UV :</div><div class="item-count" id="busuanzi_value_site_uv"></div></div><div class="webinfo-item"><div class="item-name">PV :</div><div class="item-count" id="busuanzi_value_site_pv"></div></div><div class="webinfo-item"><div class="item-name">Last Push :</div><div class="item-count" id="last-push-date" data-lastPushDate="2022-01-17T06:06:45.477Z"></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By CodingDGSun</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/codingdgsun/js/utils.js"></script><script src="/codingdgsun/js/main.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>